﻿using Fozzy.Being;
using Fozzy.Ontology;
using System.Collections.Generic;
using System.Linq;

namespace Fozzy.Gedcom
{
    /// <summary>
    /// One family group. 
    /// </summary>
    [XAlias("FAM")]
    [XLevel(0)]
    public class Family                         : Fozzy.Being.Family
    {
        #region fields

        #endregion

        #region States
        #endregion

        #region Structure
            private Fozzy.Being.Parents         Parents                 { get { return Value                                                    ; } }
            private Enumeration<Being.Person>   Children                { get { return Parts                                                    ; } }
        #endregion

        #region Name
        #endregion

        #region Properties
            private Header                      Header                  { get { return Identifier.Header(Name)                                  ; } }
            public new Identifier               Identifier              { get { return new Identifier(Element)                                  ; } }
        #endregion

        #region Relations
        #endregion

        #region Constructeur

            //public Family(Person parentLeft, Person parentRight)        : base(new Couple(parentLeft, parentRight))
            //{
            //    //this.parentLeft = parentLeft;
            //    //this.parentRight = parentRight;
            //}
            public Family()
            {}
            public Family(_Element node)                                 : this(new Parents(node), new Children(node))
            {}
            public Family(Parents parents, Children children)           : base(parents, children.Instances)
            {}

        #endregion

            public void Parent(Person parent)
            {
                Parents.Add(parent)                                     ;
            }

            //Argh :family.OnContentChanged(newPerson);
            public void Child(Person child)
            {
                Children.Add(child)                                     ;
            }

            //Argh :family.OnContentChanged(newPerson);
            public void Sibling(Person sibling)
            {
                Child(sibling)                                          ;
            }

            //Argh :family.OnContentChanged(newPerson);
            public void Spouse(Person spouse)
            {
                Parent(spouse)                                          ;
            }

            //public override void Export(Fozzy.File file)
            //{
            //    base    .Export(file)                                   ;
            //    Header  .Export(file)                                   ;
            //    Parents .Export(file)                                   ;
            //    Children.Export(file)                                   ;
            //}

        //private void ExportFamily(Family family)
        //{
        //    // Return right away if this is only a single person without any children.
        //    if (family.ParentRight == null && family.Children.Count == 0)
        //        return;

        //    // Start of new family record.
        //    WriteLine(0, string.Format(CultureInfo.InvariantCulture, "@F{0}@", familyId++), "FAM");

        //    // Marriage info.
        //    ExportMarriage(family.ParentLeft, family.ParentRight, family.Relationship);

        //    // Children.
        //    foreach (Person child in family.Children)
        //    {
        //        WriteLine(1, "CHIL", string.Format(
        //            CultureInfo.InvariantCulture, "@{0}@", idMap.Get(child.Id)));
        //    }
        //}

    }
}
